package com.yuexunit.finance.member.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.member.entity.LogisticsCompanyInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年6月12日 下午3:44:40
*@author wenwenlong
*类说明
*/

@Implements(LogisticsCompanyInfoService.class)
public class LogisticsCompanyInfoServiceImpl implements LogisticsCompanyInfoService {

	@Override
	@Transactional
	public Long createLogisticsCompanyInfo(LogisticsCompanyInfoEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		entity.setEnabled(Boolean.TRUE);
		PersistUtil.insert(entity);
		return entity.getLogisticsCompanyInfoId();
	}

	@Override
	@Transactional
	public void updateLogisticsCompanyInfo(LogisticsCompanyInfoEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public LogisticsCompanyInfoEntity inquireLogisticsCompanyInfo(Long logisticsCompanyId) {
		return PersistUtil.get(LogisticsCompanyInfoEntity.class, logisticsCompanyId);
	}

	@Override
	@Transactional
	public void disableLogisticsCompanyInfo(Long logisticsCompanyId) {
		LogisticsCompanyInfoEntity entity = PersistUtil.get(LogisticsCompanyInfoEntity.class, logisticsCompanyId);
		entity.setUpdateDateTime(DateUtil.now());
		entity.setEnabled(Boolean.FALSE);
		PersistUtil.update(entity);
	}

	@Override
	public List<LogisticsCompanyInfoEntity> inquireLogisticsCompanyInfoList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(LogisticsCompanyInfoEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<LogisticsCompanyInfoEntity> inquireLogisticsCompanyInfoPageList(PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(LogisticsCompanyInfoEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		return PersistUtil.get(criteria, page);
	}

	@Override
	public List<LogisticsCompanyInfoEntity> inquireLogisticsCompanyByName(
			String logisticsCompanyName) {
		DetachedCriteria criteria = DetachedCriteria.forClass(LogisticsCompanyInfoEntity.class);
		criteria.add(Restrictions.eq("logisticsCompanyName", logisticsCompanyName));
		return PersistUtil.get(criteria);
	}
}
